// -----------------------------
// Author: 		Dhaenens Gert 
// Creation: 	2/22/2015 12:39:01 PM				
// -----------------------------

#ifndef _TextureLoader_h
#define _TextureLoader_h

#include "Job.h"

#include "zlib.h"
#include "png.h"

namespace Flow
{

	class IGraphicsDevice;
	class IMutex;
	class ITexture;

	class File;

	class TextureLoader : public Job
	{
	public:

		static void		LoadLock();
		static void		UnloadLock();

		TextureLoader(IGraphicsDevice* lpDevice, IMutex* lpGraphicsMutex, const tstring& file);
		virtual ~TextureLoader();

		ITexture*		Load();
		virtual void	Run();

	private:

		static IMutex*		s_LibPNGLock;

		IGraphicsDevice*	m_lpGraphicsDevice;
		IMutex*				m_lpGraphicsMutex;

		ITexture*			m_lpTexture;
		tstring				m_FilePath;
		File*				m_lpFile;

		void*			ReadPNGData(UInt32& out_Width, UInt32& out_Height, TextureFormat::Enum& out_Format);
		static void		readUserData(png_structp pngPtr, png_bytep data, png_size_t length);
		static Byte*	ConvertR8B8G8(Byte* lpData, UInt32 width, UInt32 height);
		static Byte*	ConvertR32B32G32(Byte* lpData, UInt32 width, UInt32 height);
		static Byte*	ConvertR32B32G32A32(Byte* lpData, UInt32 width, UInt32 height);

		TextureLoader(const TextureLoader& refTextureLoader);
		TextureLoader& operator=(const TextureLoader& refTextureLoader);

	};

}

#endif